<template>
	<view class="content">
		<view class="info">
			<view class="item">
				<view>姓名</view>
				<input type="text" placeholder="请输入姓名" v-model="j_name" />
			</view>
			<view class="item">
				<view>手机号</view>
				<input type="text" placeholder="请输入手机号" v-model="j_phone" />
			</view>
			<view class="item">
				<view>单位名称</view>
				<input type="text" placeholder="请输入单位名称" v-model="j_company" />
			</view>
			<view class="item">
				<view>职业状态</view>
				<uni-data-select v-model="j_state" :localdata="career" @change="change"></uni-data-select>
			</view>
			<!-- <view class="item">
				<view>工作城市</view>
				<uni-data-select v-model="j_city" :localdata="range" @change="change"></uni-data-select>
			</view> -->
			<view class="item">
				<view>公司类别</view>
				<uni-data-select v-model="j_classes" :localdata="company_type" @change="change"></uni-data-select>
			</view>
			<view class="item">
				<view>公司行业</view>
				<uni-data-select v-model="j_industry" :localdata="company_industry" @change="change"></uni-data-select>
			</view>
			<view class="item">
				<view>公司规模</view>
				<uni-data-select v-model="j_scale" :localdata="company_gm" @change="change"></uni-data-select>
			</view>
			<view class="item">
				<view>职位</view>
				<input type="text" placeholder="请输入职位" v-model="j_position" />
			</view>
			<view class="item">
				<view>月收入</view>
				<uni-data-select v-model="j_income" :localdata="company_size" @change="change"></uni-data-select>
			</view>
			<view class="item">
				<view>工作年限</view>
				<uni-data-select v-model="j_age" :localdata="work_year" @change="changez"></uni-data-select>
			</view>
			<view class="item">
				<view>工作邮箱</view>
				<input type="text" placeholder="请输入工作邮箱" v-model="j_email" />
			</view>
			<view class="item">
				<view>公司地址</view>
				<input type="text" placeholder="请输入公司地址" v-model="j_address" />
			</view>
		</view>
		<view class="info">
			<view class="title">直系亲属联系人</view>
			<view class="item">
				<view>姓名</view>
				<input type="text" placeholder="请输入姓名" v-model="z_name" />
			</view>
			<view class="item">
				<view>关系</view>
				<input type="text" placeholder="请输入您与此联系人之间的关系" v-model="z_relation" />
			</view>
			<view class="item">
				<view>手机号</view>
				<input type="text" placeholder="请输入手机号" v-model="z_phone" />
			</view>
		</view>
		<view class="info">
			<view class="title">其他联系人</view>
			<view class="item">
				<view>姓名</view>
				<input type="text" placeholder="请输入姓名" v-model="q_name" />
			</view>
			<view class="item">
				<view>关系</view>
				<input type="text" placeholder="请输入您与此联系人之间的关系" v-model="q_relation" />
			</view>
			<view class="item">
				<view>手机号</view>
				<input type="text" placeholder="请输入手机号" v-model="q_phone" />
			</view>
		</view>
		<view class="default_btn btn" @click="save">保存</view>
	</view>
</template>

<script>
	import {
		applyLoan,
		payPassword,
		clientSelect,
		clientSave
	} from "@/common/js/index.js"
	export default {
		data() {
			return {
				j_name: '',
				j_phone: '',
				j_company: '',
				j_state: '',
				j_city: '',
				j_classes: '',
				j_industry: '',
				j_scale: '',
				j_position: '',
				j_income: '',
				j_age: '',
				j_email: '',
				j_address: '',

				z_name: '',
				z_relation: '',
				z_phone: '',

				q_name: '',
				q_relation: '',
				q_phone: '',

				selInfo: '',
				career: [],
				company_industry: [],
				company_size: [],
				company_type: [],
				work_year: [],
				company_gm: [],

				range: [],
				userId: ''

			}
		},
		onLoad(e) {
			var info = JSON.parse(e.info)
			console.log(info);
			this.j_name = info.real_name
			this.j_phone = info.mobile
			this.j_company = info.office
			this.userId = info.id
			if (info.work) {
				this.j_state = info.work.jobtype
				// this.j_city = info.work.
				this.j_classes = info.work.officetype
				this.j_industry = info.work.officedomain
				this.j_scale = info.work.officecale
				this.j_position = info.work.position
				this.j_income = info.work.salary
				this.j_age = info.work.workyears
				this.j_email = info.work.workemail
				this.j_address = info.work.officeaddress
				this.z_name = info.work.urgentcontact
				this.z_relation = info.work.urgentrelation
				this.z_phone = info.work.urgentmobile
				this.q_name = info.work.urgentcontact2
				this.q_relation = info.work.urgentrelation2
				this.q_phone = info.work.urgentmobile2
			}
			this.select()
		},
		methods: {
			// clientSelect() 
			passwordYn() {
				console.log(this.value2);
				var hint
				if (!this.name) {
					hint = '请输入借款人姓名'
				} else if (!hint && !this.card) {
					hint = '请输入身份证号'
				} else if (!hint && !this.phone) {
					hint = '请输入手机号'
				} else if (!hint && !this.value) {
					hint = '请选择借款用途'
				} else if (!hint && !this.value3) {
					hint = '请选择借款周期'
				} else if (!hint && !this.rate) {
					hint = '请输入利息'
				} else if (!hint && this.value2 === '') {
					hint = '请选择还款方式'
				} else if (!hint && !this.description) {
					hint = '请输入借款描述'
				} else if (!hint && !this.checkbox1) {
					hint = '请先阅读并同意《借款协议》'
				}
				if (!hint && !this.checkbox1) {
					if (this.value3 == 1 && !this.day) hint = '请输入借款期限'
					else if (this.value3 == 2 && (!this.week || this.day_demo)) hint = '请完善借款期限'
					else if (this.value3 == 3 && !this.month) hint = '请选择借款期限'
				}
				if (hint) {
					uni.showToast({
						title: hint,
						icon: 'none',
						duration: 3000
					})
					return
				}
				this.$refs.popup.open('center')
			},
			changez(e) {

			},
			change(e) {
				console.log("e:", e);
			},
			save() {
				var info = {
					user_id: this.userId,
					real_name: this.j_name,
					mobile: this.j_phone,
					office: this.j_company,
					jobtype: this.j_state,
					officetype: this.j_classes,
					officedomain: this.j_industry,
					officecale: this.j_scale,
					position: this.j_position,
					salary: this.j_income,
					workyears: this.j_age,
					workemail: this.j_email,
					officeaddress: this.j_address,
					urgentcontact: this.z_name,
					urgentrelation: this.z_relation,
					urgentmobile: this.z_phone,
					urgentcontact2: this.q_name,
					urgentrelation2: this.q_relation,
					urgentmobile2: this.q_phone,
				}
				clientSave(info).then(res => {
					console.log(res);
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 200) {
						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					}
				})
			},
			select() {
				clientSelect().then(res => {
					var list = res.data
					for (var i = 0; i < list.career.length; i++) {
						var info = {
							value: list.career[i],
							text: list.career[i]
						}
						this.career.push(info)
					}
					console.log(this.career);
					for (var i = 0; i < list.company_industry.length; i++) {
						var info = {
							value: list.company_industry[i],
							text: list.company_industry[i]
						}
						this.company_industry.push(info)
					}
					console.log(this.company_industry);
					for (var i = 0; i < list.company_size.length; i++) {
						var info = {
							value: list.company_size[i],
							text: list.company_size[i]
						}
						this.company_size.push(info)
					}
					console.log(this.company_size);
					for (var i = 0; i < list.company_type.length; i++) {
						var info = {
							value: list.company_type[i],
							text: list.company_type[i]
						}
						this.company_type.push(info)
					}
					console.log(this.company_type);
					for (var i = 0; i < list.work_year.length; i++) {
						var info = {
							value: list.work_year[i],
							text: list.work_year[i]
						}
						this.work_year.push(info)
					}
					console.log(this.work_year);
					for (var i = 0; i < list.company_gm.length; i++) {
						var info = {
							value: list.company_gm[i],
							text: list.company_gm[i]
						}
						this.company_gm.push(info)
					}
					console.log(this.company_gm);
				})
			}
		},
		onPageScroll(e) {},
	}
</script>

<style scoped lang="scss">
	.content {
		position: relative;
		overflow: hidden;
	}

	.info {
		margin: 40rpx 30rpx;
		padding: 0 30rpx 40rpx;
		background-color: white;
		background: #FFFFFF;
		border-radius: 12rpx;

		// overflow: hidden;
		.title {
			font-weight: 500;
			font-size: 32rpx;
			text-align: center;
			padding-top: 30rpx;
		}

		.item {
			height: 100rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 28rpx;
			border-bottom: 2rpx solid #EEEEEE;

			input {
				flex: 1;
				text-align: right;
				font-size: 26rpx;
			}
		}
	}

	/deep/.uni-select {
		margin-left: auto;
		width: 300rpx;
		text-align: right;
		border: none;
	}

	/deep/ .uni-select__selector-item {
		display: block;
		text-align: right !important;
	}

	.btn {
		margin: 80rpx auto 150rpx;
	}
</style>